#include "about.h"
#include <QtGui>

About::About(QWidget *parent):
    QDialog(parent)
{
    setModal(true);
    setMinimumSize(500, 500);
    setWindowTitle(qApp->property("appRealName").toString() + "::" + "About");

    QLabel *logo = new QLabel(this);
        logo->setPixmap(QPixmap(":/images/logo.png"));
    QLabel *appName = new QLabel(this);
        appName->setText("<h1>" + qApp->property("appRealName").toString() + "</h1>");
    QLabel *appVersion = new QLabel(this);
        appVersion->setText("<h3><b>" + tr("Version: ") + qApp->applicationVersion() + "</b></h3>");

    QWidget *autorTab = new QWidget(this);
        QTextBrowser *autorTextB = new QTextBrowser(this);
            autorTextB->setHtml(strFromFile(":ABOUT"));
            autorTextB->setOpenExternalLinks(true);

        QGridLayout *autorLayout = new QGridLayout();
            autorLayout->addWidget(autorTextB);
    autorTab->setLayout(autorLayout);

    QWidget *licenseTab = new QWidget(this);
        QTextBrowser *licenseTextB = new QTextBrowser(this);
            licenseTextB->setText(strFromFile(":LICENSE.html"));

        QGridLayout *licenseLayout = new QGridLayout();
            licenseLayout->addWidget(licenseTextB);
    licenseTab->setLayout(licenseLayout);


    QTabWidget *tabs = new QTabWidget(this);
        tabs->addTab(autorTab, tr("Info"));
        tabs->addTab(licenseTab, tr("License"));

    QVBoxLayout *logoLayout = new QVBoxLayout();
        logoLayout->addWidget(logo);
        logoLayout->addStretch(1);
    QVBoxLayout *appLayout = new QVBoxLayout();
        appLayout->addWidget(appName);
        appLayout->addWidget(appVersion);
        appLayout->addStretch(1);

    QHBoxLayout *topLayout = new QHBoxLayout();
        topLayout->addLayout(logoLayout);
        topLayout->addLayout(appLayout);
        topLayout->addStretch(1);

    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->addLayout(topLayout);
    mainLayout->addWidget(tabs, 1);

    setLayout(mainLayout);
}

QString About::strFromFile(const QString &filename)
{
    QString str = "";
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
         return str;
    return QString(file.readAll());
}

About::~About()
{

}
